import { InputQuestion, QuestionBase, SelectQuestion, TimeQuestion } from '@/components/public-template';
import { TextTable } from '@/components/public-template';
import { TableBase } from '@/components/public-template';
import { Api } from '@/config/api/fileQuery';

class HomeService {
  getQuestions() {
    const questions: QuestionBase<any>[] = [
      new InputQuestion({
        key: 'name',
        label: '文件名称',
        value: null
      }),
      new InputQuestion({
        key: 'code',
        label: '文件编码',
        value: null
      }),
      new SelectQuestion({
        key: 'status',
        label: '文件状态',
        value: [],
        defaultValue: [],
        type: 'dictionary',
        state: {
          mode: 'multiple',
          filterName: 'DMS_PUBILC_FILE_INFO_STATUS'
        }
      }),
      new TimeQuestion({
        key: 'startEffectTime',
        label: '生效日期',
        value: null,
        state: {
          valueFormat: 'YYYY-MM-DD',
          format: 'YYYY-MM-DD',
          keySplit: ['startEffectTime', 'endEffectTime']
        }
      }),
      new InputQuestion({
        key: 'keyword',
        label: '关键字',
        value: null
      }),
      new InputQuestion({
        key: 'mainContent',
        label: '主要内容',
        value: null
      }),
      new SelectQuestion({
        key: 'directoryIds',
        label: '文件类型',
        prompt: '请选择',
        value: [],
        type: 'tree',
        state: {
          url: Api.advancedQueryArchivesTypeTree,
          protType: 'post',
          nameKey: 'name',
          nameValue: 'id',
          nameChildren: 'children',
          multiple: true,
          expandAll: true
        }
      })
    ];
    return questions;
  }
  getTables() {
    const tables: TableBase<any>[] = [
      new TextTable({
        key: 'name',
        value: '文件名称'
      }),
      new TextTable({
        key: 'code',
        value: '文件编码'
      }),
      new TextTable({
        key: 'version',
        value: '版本号'
      }),
      new TextTable({
        key: 'directoryName',
        value: '文件类型'
      }),
      new TextTable({
        key: 'status',
        value: '文件状态',
        type: 'dictionary',
        state: {
          mode: 'multiple',
          filterName: 'DMS_PUBILC_FILE_INFO_STATUS'
        }
      }),
      new TextTable({
        key: 'effectTime',
        value: '生效日期'
      }),
      new TextTable({
        key: 'keyword',
        value: '关键字'
      }),
      new TextTable({
        key: 'mainContent',
        value: '主要内容'
      }),
      new TextTable({
        key: 'previewNum',
        value: '预览次数'
      }),
      new TextTable({
        key: 'downloadNum',
        value: '下载次数'
      }),
      new TextTable({
        key: 'actions',
        value: '操作',
        columns: {
          fixed: 'right',
          width: 240
        },
        handle: [
          {
            type: 'local',
            text: '预览',
            class: 'text-primary',
            params: [{ id: 'id' }],
            state: {
              name: 'preview'
            },
            showKey: [{ key: 'couldPreview', value: true }]
          },
          {
            type: 'local',
            text: '下载',
            class: 'text-primary',
            params: [{ id: 'id' }],
            state: {},
            showKey: [{ key: 'couldDownload', value: true }]
          },
          {
            type: 'local',
            text: '历史版本',
            class: 'text-primary',
            params: [{ id: 'id' }],
            state: {}
          }
        ]
      })
    ];
    return tables;
  }
  getIcons() {
    const icons: TableBase<any>[] = [
      new TextTable({
        key: 'local',
        value: '下载',
        type: 'primary',
        class: 'icon-download',
        state: {}
      })
    ];
    return icons;
  }
}

export default new HomeService();
